package groupby.manage;

import groupby.model.GroupCriticism;
import groupby.model.GroupUserCriticism;
import groupby.persistence.GroupCriticismDao;
import groupby.util.Pages;

import java.util.ArrayList;
import java.util.List;

import user.model.UserDetial;
import user.model.Users;
import user.persistence.UsersDao;

public class GroupCriticismManageImpl implements GroupCriticismManage {
    private GroupCriticismDao groupCriticismDao=null;
    private UsersDao userDao=null;
    
	public boolean addGroupCriticism(GroupCriticism groupCriticism) {
		boolean isSuccess=groupCriticismDao.addGroupCriticism(groupCriticism);
		return true;
	}

	public int count(String id) {
		return groupCriticismDao.count(id);
		 
	}

	public GroupCriticismDao getGroupCriticismDao() {
		return groupCriticismDao;
	}

	public void setGroupCriticismDao(GroupCriticismDao groupCriticismDao) {
		this.groupCriticismDao = groupCriticismDao;
	}

	/**
	 * 获得团购活动评论列表
	 * @param groupbyId
	 * @return
	 */
	public List getGroupbyCriticismList(int groupbyId,Pages pages) {
		List list=groupCriticismDao.getGroupbyCriticismList(groupbyId,pages);
        List listGroupbyCriticism=new ArrayList();
		
		for(int i=0;i<list.size();i++)
		{
			String[] groupbyCriticismStr=new String[7];
			GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
			groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
			groupbyCriticismStr[1]=groupbyCriticism.getContent();
			groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
			UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
			Users user=userDao.getUsers(userDetial.getUserId());
			groupbyCriticismStr[3]=userDetial.getImage();
			groupbyCriticismStr[4]=userDetial.getUsername();
			groupbyCriticismStr[5]=user.getId().toString();
			groupbyCriticismStr[6]=user.getLevel().toString();
			
			listGroupbyCriticism.add(groupbyCriticismStr);
		}
		return listGroupbyCriticism;
	}

	public UsersDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UsersDao userDao) {
		this.userDao = userDao;
	}

	/**
	 *  获得最新评论
	 */
	public List getNewGroupbyCriticism(Pages pages) {
		List list=groupCriticismDao.getNewGroupbyCriticism(pages);
        List listGroupbyCriticism=new ArrayList();
		
		for(int i=0;i<list.size();i++)
		{
			String[] groupbyCriticismStr=new String[9];
			GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
			groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
			groupbyCriticismStr[1]=groupbyCriticism.getContent();
			groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
			UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
			Users user=userDao.getUsers(userDetial.getUserId());
			groupbyCriticismStr[3]=userDetial.getImage();
			groupbyCriticismStr[4]=userDetial.getUsername();
			groupbyCriticismStr[5]=user.getId().toString();
			groupbyCriticismStr[6]=user.getLevel().toString();
			groupbyCriticismStr[7]=groupbyCriticism.getGroupbyId().toString();
			groupbyCriticismStr[8]=groupbyCriticism.getUrl();
			listGroupbyCriticism.add(groupbyCriticismStr);
		}
		return listGroupbyCriticism;
	}
    /**
     * 获得最新团购用户评论
     */
	public List getGroupbyUserCriticismList(int groupbyUserId, Pages pages) {
		List list=groupCriticismDao.getGroupbyUserCriticismList(groupbyUserId,pages);
		List listGroupbyCriticism=new ArrayList();
		
		for(int i=0;i<list.size();i++)
		{
			String[] groupbyCriticismStr=new String[8];
			GroupUserCriticism groupbyCriticism=(GroupUserCriticism)list.get(i);
			groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
			groupbyCriticismStr[1]=groupbyCriticism.getContent();
			groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
			UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
			Users user=userDao.getUsers(userDetial.getUserId());
			groupbyCriticismStr[3]=userDetial.getImage();
			groupbyCriticismStr[4]=userDetial.getUsername();
			groupbyCriticismStr[5]=user.getId().toString();
			groupbyCriticismStr[6]=user.getLevel().toString();
			groupbyCriticismStr[7]=groupbyCriticism.getUrl();
			listGroupbyCriticism.add(groupbyCriticismStr);
		}
		return listGroupbyCriticism;
	}

	/**
	 * add groupby User Criticism
	 */
	public boolean addGroupUserCriticism(GroupUserCriticism groupCriticism) {
		
		boolean isSuccess=groupCriticismDao.addGroupUserCriticism(groupCriticism);
		return isSuccess;
	}
/**
 * 获得相册图片回应列表
 */
	public List criticismPhotoList(Pages pages,Integer id) {
		List list=groupCriticismDao.criticismPhotoList(pages,id);
        List listGroupbyCriticism=new ArrayList();
		
		for(int i=0;i<list.size();i++)
		{
			String[] groupbyCriticismStr=new String[9];
			GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
			groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
			groupbyCriticismStr[1]=groupbyCriticism.getContent();
			groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
			UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
			Users user=userDao.getUsers(userDetial.getUserId());
			groupbyCriticismStr[3]=userDetial.getImage();
			groupbyCriticismStr[4]=userDetial.getUsername();
			groupbyCriticismStr[5]=user.getId().toString();
			groupbyCriticismStr[6]=user.getLevel().toString();
			groupbyCriticismStr[7]=groupbyCriticism.getGroupbyId().toString();
			groupbyCriticismStr[8]=groupbyCriticism.getUrl();
			listGroupbyCriticism.add(groupbyCriticismStr);
		}
		return listGroupbyCriticism;
	}
/**
 * 获得单个相册的最新评论
 */
public List newCriticismPhotoList(Pages pages, String picId) {
	List list=groupCriticismDao.newCriticismPhotoList(pages,picId);
	
	List listGroupbyCriticism=new ArrayList();
	
	for(int i=0;i<list.size();i++)
	{
		String[] groupbyCriticismStr=new String[8];
		GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
		groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
		groupbyCriticismStr[1]=groupbyCriticism.getContent();
		groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
		UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
		Users user=userDao.getUsers(userDetial.getUserId());
		groupbyCriticismStr[3]=userDetial.getImage();
		groupbyCriticismStr[4]=userDetial.getUsername();
		groupbyCriticismStr[5]=user.getId().toString();
		groupbyCriticismStr[6]=user.getLevel().toString();
		groupbyCriticismStr[7]=groupbyCriticism.getUrl();
		listGroupbyCriticism.add(groupbyCriticismStr);
	}
	return listGroupbyCriticism;
	
}
/**
 * 获得品牌评论信息
 */
public List criticismBrandList(Pages pages, int brandId, int id) {
	List list=groupCriticismDao.criticismBrandList(pages,brandId,id);
List listGroupbyCriticism=new ArrayList();
	
	for(int i=0;i<list.size();i++)
	{
		String[] groupbyCriticismStr=new String[8];
		GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
		groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
		groupbyCriticismStr[1]=groupbyCriticism.getContent();
		groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
		UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
		Users user=userDao.getUsers(userDetial.getUserId());
		groupbyCriticismStr[3]=userDetial.getImage();
		groupbyCriticismStr[4]=userDetial.getUsername();
		groupbyCriticismStr[5]=user.getId().toString();
		groupbyCriticismStr[6]=user.getLevel().toString();
		groupbyCriticismStr[7]=groupbyCriticism.getUrl();
		listGroupbyCriticism.add(groupbyCriticismStr);
	}
	return listGroupbyCriticism;
}
/**
 * 获得最品牌新评论信息
 */
public List brandNewCriticismList(Pages pages, String brandId) {
	List list=groupCriticismDao.brandNewCriticismList(pages,brandId);
List listGroupbyCriticism=new ArrayList();
	
	for(int i=0;i<list.size();i++)
	{
		String[] groupbyCriticismStr=new String[8];
		GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
		groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
		groupbyCriticismStr[1]=groupbyCriticism.getContent();
		groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
		UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
		Users user=userDao.getUsers(userDetial.getUserId());
		groupbyCriticismStr[3]=userDetial.getImage();
		groupbyCriticismStr[4]=userDetial.getUsername();
		groupbyCriticismStr[5]=user.getId().toString();
		groupbyCriticismStr[6]=user.getLevel().toString();
		groupbyCriticismStr[7]=groupbyCriticism.getUrl();
		listGroupbyCriticism.add(groupbyCriticismStr);
	}
	return listGroupbyCriticism;
}
/**
 * 获得话题评论信息
 */
public List criticismTopicList(Pages pagesTemp, String topicId, int id) {
	List list=groupCriticismDao.criticismTopicList(pagesTemp,topicId,id);
List listGroupbyCriticism=new ArrayList();
	
	for(int i=0;i<list.size();i++)
	{
		String[] groupbyCriticismStr=new String[8];
		GroupCriticism groupbyCriticism=(GroupCriticism)list.get(i);
		groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
		groupbyCriticismStr[1]=groupbyCriticism.getContent();
		groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
		UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
		Users user=userDao.getUsers(userDetial.getUserId());
		groupbyCriticismStr[3]=userDetial.getImage();
		groupbyCriticismStr[4]=userDetial.getUsername();
		groupbyCriticismStr[5]=user.getId().toString();
		groupbyCriticismStr[6]=user.getLevel().toString();
		groupbyCriticismStr[7]=groupbyCriticism.getUrl();
		listGroupbyCriticism.add(groupbyCriticismStr);
	}
	return listGroupbyCriticism;
}
/**
 * 获得留言列表
 */
public List feedBack(Pages pageTemp, int userId) {
List list=groupCriticismDao.feedBack(pageTemp,userId);
	
	List listGroupbyCriticism=new ArrayList();
	
	for(int i=0;i<list.size();i++)
	{
		String[] groupbyCriticismStr=new String[8];
		GroupUserCriticism groupbyCriticism=(GroupUserCriticism)list.get(i);
		groupbyCriticismStr[0]=groupbyCriticism.getId().toString();
		groupbyCriticismStr[1]=groupbyCriticism.getContent();
		groupbyCriticismStr[2]=groupbyCriticism.getDatetime();
		UserDetial userDetial=userDao.getSingleUser(groupbyCriticism.getUserId());
		Users user=userDao.getUsers(userDetial.getUserId());
		groupbyCriticismStr[3]=userDetial.getImage();
		groupbyCriticismStr[4]=userDetial.getUsername();
		groupbyCriticismStr[5]=user.getId().toString();
		groupbyCriticismStr[6]=user.getLevel().toString();
		groupbyCriticismStr[7]=groupbyCriticism.getUrl();
		listGroupbyCriticism.add(groupbyCriticismStr);
	}
	return listGroupbyCriticism;
}

}
